package com.it.map_impl;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

/**
 * 目标：掌握TreeMap集合的使用
 */
public class TestTreeMap {
    public static void main(String[] args) {
        Map<Student,String> map = new TreeMap<>(new Comparator<Student>() {
                    @Override
                    public int compare(Student o1, Student o2) {
                        return Double.compare(o2.getHeight(), o1.getHeight()); // 按身高降序排序
                    }
                }
        );
//  简化代码：Map<Student,String> map = new TreeMap<>((o1,o2) -> Double.compare(o2.getHeight(), o1.getHeight())
        map.put(new Student("至尊宝", 28, 169.9), "水帘洞");
        map.put(new Student("蜘蛛精", 23, 160.9), "盘丝洞");
        map.put(new Student("紫霞", 26, 150.9), "黑熊洞");
        map.put(new Student("牛魔二", 26, 180.9), "牛头山");
        System.out.println(map);
    }
}
